/**
 * Created by jiadx on 2015/11/13.
 */

requirejs.config({
    baseUrl: '../www',
    paths: {
        app: 'js/app',
        ionic: u9.toU9URL('lib/ionic/js/ionic.bundle'),
        ionicU9: 'lib/ionicU9/ionicU9',
        pinyin: 'lib/pinyin/pinyin',
        microsoftAjax: u9.toU9URL('lib/MicrosoftAjax')
    },
    shim: {
        ionicU9: {
            deps: ['ionic']
        }
    }
});

// Start the main app logic.
requirejs(['pinyin'], function () {
    requirejs(['app', 'microsoftAjax'], function () {
        u9.callSVAlone = function (jsonData) {
            var svFullName = jsonData['name'],
                params = jsonData['params'],
                address = u9.getConnectSetting().address,
                port = u9.getConnectSetting().port,
                url = 'http://' + address + ':' + port + '/svc_script/' + '?n=' + svFullName + '&p=null';
            var onSuccess = function (data) {
            };
            var onFailure = function (data) {
            };
            return require([url], function (bpObj) {
                params.unshift({
                    EntCode: u9.getLoginData().EntCode,
                    OrgCode: u9.getLoginData().OrgCode,
                    OrgId: u9.getLoginData().OrgId,
                    UserCode: u9.getLoginData().UserCode,
                    CultureName: 'zh-CN'
                });
                if (jsonData['onSuccess']) {
                    params.push(jsonData['onSuccess']);
                } else {
                    params.push(onSuccess);
                }
                if (jsonData['onFailure']) {
                    params.push(jsonData['onFailure']);
                } else {
                    params.push(onFailure);
                }

                var svcProxy = 'http://' + address + ':' + port + '/u9_gateway/RestServices/' + svFullName + '.svc';
                try {
                    bpObj.set_path(svcProxy);
                    return bpObj.Do.apply(bpObj, params);
                } catch (e) {
                    return jsonData.onFailure(e);
                }
            });
        };
        angular.element(document).ready(function () {
            angular.bootstrap(document, ['SalesShipments']);
        });
    });
});